module ProgramLogic;
import renderers.Model;
import framework.Events;
import framework.JobHub;
import frontend.Types;
import std.c.stdlib;
import derelict.sdl.sdl;
import frontend.Model;
import maths.Vec;
import frontend.ModelCache;


class ProgramLogic{
	ModelRenderer modelRender;
	/+ModelRenderer modelRender2;
	ModelRenderer modelRender3;
	ModelRenderer modelRender4;
	ModelRenderer modelRender6;
	ModelRenderer modelRender5;+/
	
	this(){
		Model m1= modelCache.loadModel("models/soldier.dmc");
		m1.skeleton.setAnimation("soldier-dance", true);
		m1.skeleton.setStandardAnimation("soldier-dance");
		
		/+Model m2= modelCache.loadModel("models/soldier.dmc");
		
		m2.skeleton.setAnimation("soldier-arm", true);
		m2.skeleton.setStandardAnimation("soldier-arm");
		m2.coordSys.origin=vec3fi[3.f,0.f,0.f];
		
		Model m3= modelCache.loadModel("models/soldier.dmc");
		m3.skeleton.setAnimation("soldier-arm", true);
		m3.skeleton.setAnimationTime("soldier-arm",0.5);
		m3.skeleton.setStandardAnimation("soldier-arm");
		m3.coordSys.origin=vec3fi[-3.f,0.f,0.f];
		
		Model m4= modelCache.loadModel("models/soldier.dmc");
		m4.skeleton.setAnimation("soldier-leg", true);
		m4.skeleton.setAnimationTime("soldier-leg",0.5);
		m4.skeleton.setStandardAnimation("soldier-leg");
		m4.coordSys.origin=vec3fi[0.f, 0.f, 3.f];
		
		Model m5= modelCache.loadModel("models/soldier.dmc");
		m5.skeleton.setAnimation("soldier-arm", true);
		m5.skeleton.setAnimationTime("soldier-arm",0.25);
		m5.skeleton.setStandardAnimation("soldier-arm");
		m5.coordSys.origin=vec3fi[3.f,0.f,3.f];
		
		Model m6= modelCache.loadModel("models/soldier.dmc");
		m6.skeleton.setAnimation("soldier-leg", true);
		m6.skeleton.setAnimationTime("soldier-leg",0.25);
		m6.skeleton.setStandardAnimation("soldier-leg");
		m6.coordSys.origin=vec3fi[-3.f,0.f,3.f];+/
		
		/+Skeleton.central.setGetCoord(m2.skeleton,&m2.getCoordSys);
		Skeleton.central.setGetCoord(m3.skeleton,&m3.getCoordSys);
		Skeleton.central.setGetCoord(m4.skeleton,&m4.getCoordSys);
		Skeleton.central.setGetCoord(m5.skeleton,&m5.getCoordSys);
		Skeleton.central.setGetCoord(m6.skeleton,&m6.getCoordSys);+/
		
		jobHub.register(&Skeleton.central.update);
		modelRender=new ModelRenderer( m1 );
		/+modelRender2=new ModelRenderer( m2);
		modelRender3=new ModelRenderer( m3);
		modelRender4=new ModelRenderer( m4);
		modelRender5=new ModelRenderer( m5);
		modelRender6=new ModelRenderer( m6);+/
		
		//modelRender3=new ModelRenderer( loadModel("models/dummy.dmc"));
		eventPooler.register(&this.getKey);
		modelRender.set(ModelRendererFunc.RenderBones);
		/+modelRender2.set(ModelRendererFunc.RenderBones);
		modelRender3.set(ModelRendererFunc.RenderBones);
		modelRender4.set(ModelRendererFunc.RenderBones);
		modelRender5.set(ModelRendererFunc.RenderBones);
		modelRender6.set(ModelRendererFunc.RenderBones);+/

	}
	
	void getKey(SDL_KeyboardEvent k){
		if(k.type==SDL_KEYDOWN){
			switch(k.keysym.sym){
				case SDLK_0: modelRender.set(ModelRendererFunc.RenderNothing); 
									/+ modelRender2.set(ModelRendererFunc.RenderNothing);
									 modelRender3.set(ModelRendererFunc.RenderNothing);
									 modelRender4.set(ModelRendererFunc.RenderNothing);
									 modelRender5.set(ModelRendererFunc.RenderNothing);
									 modelRender6.set(ModelRendererFunc.RenderNothing);+/
									break;
				case SDLK_1: modelRender.set(ModelRendererFunc.RenderNotSkinned); 
									/+modelRender2.set(ModelRendererFunc.RenderNotSkinned);
									modelRender3.set(ModelRendererFunc.RenderNotSkinned);
									modelRender4.set(ModelRendererFunc.RenderNotSkinned);
									modelRender5.set(ModelRendererFunc.RenderNotSkinned);
									modelRender6.set(ModelRendererFunc.RenderNotSkinned);+/
									break;
				case SDLK_2: modelRender.set(ModelRendererFunc.RenderBones); 
									/+modelRender2.set(ModelRendererFunc.RenderBones);
									modelRender3.set(ModelRendererFunc.RenderBones);
									modelRender4.set(ModelRendererFunc.RenderBones);
									modelRender5.set(ModelRendererFunc.RenderBones);
									modelRender6.set(ModelRendererFunc.RenderBones);+/
									 break;
				case SDLK_3: modelRender.set(ModelRendererFunc.RenderSkinned); 
				                    /+modelRender2.set(ModelRendererFunc.RenderSkinned); 
				                    modelRender3.set(ModelRendererFunc.RenderSkinned); 
				                    modelRender4.set(ModelRendererFunc.RenderSkinned); 
				                    modelRender5.set(ModelRendererFunc.RenderSkinned); 
				                    modelRender6.set(ModelRendererFunc.RenderSkinned); +/
									break;
				case SDLK_ESCAPE: exit(0); break;
				default: break;
			}		
		} 
	}}